package com.botarena.client.account;

import com.botarena.client.SiteTokens;
import com.botarena.shared.UserInfo;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Ogolne GUI wyswietlajace informacje o uzytkowniku
 * 
 * @author quermit, wirenth
 * 
 */
public class AccountViewer {

	public static Panel createAccountBar(final UserInfo userInfo) {
		HorizontalPanel panel = new HorizontalPanel();

		Anchor account = new Anchor("Account", SiteTokens
				.hashToken(SiteTokens.ACCOUNT));
		
		if (userInfo.isLoggedIn()) {
			if (userInfo.hasAccount()) {
				panel.add(new Label("Logged in as " + userInfo.getName()));
				panel.add(account);
			} else {
				panel.add(new Label("Logged in as (google user) "
						+ userInfo.getNickname()));
			}
			panel.add(new Anchor("Sign out", userInfo.getLogoutUrl()));
		} else {
			panel.add(new Label("Not logged in"));
			panel.add(new Anchor("Sign in using a Google Account", userInfo
					.getLoginUrl()));
		}

		return panel;
	}

	public static Panel createAccountPage(UserInfo userInfo) {
		Panel panel = new VerticalPanel();
		
		Label title = new Label("Account settings");
		title.setStyleName("title");
		panel.add(title);
		
		Label comment = new Label("Edit your account settings");
		comment.setStyleName("title5");
		panel.add(comment);
		
		panel.add(AccountEditor.createEditForm(userInfo));
		
		return panel;
	}

	public static Panel createUserPage(String userKey) {
		VerticalPanel panel = new VerticalPanel();
		
		Label title = new Label("User Homepage");
		title.setStyleName("title");
		panel.add(title);
		
		UserHomepage homepage = new UserHomepage(userKey);
		panel.add(homepage);
		
		return panel;
	}

}
